improve prompt caching by computing a deterministic hash (+ other bug fixes)#2509
improve prompt caching by computing a deterministic hash (+ other bug fixes)#2509
Conversation
WalkthroughAdds deterministic 8-character suffix generation in Go by introducing Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)frontend/app/view/codeeditor/schemaendpoints.ts (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
pkg/aiusechat/openai/openai-convertmessage.go (2)
393-399: Consider extracting hash generation to a helper function.The deterministic hashing logic works correctly for prompt caching. However, this same pattern is duplicated for directory listings (lines 422-428).
Consider extracting to a helper function:
// computeDeterministicSuffix generates an 8-character deterministic suffix // from content and name using SHA-256 hashing for prompt caching func computeDeterministicSuffix(content, name string) string { hasher := sha256.New() hasher.Write([]byte(content)) hasher.Write([]byte(name)) hash := hasher.Sum(nil) return hex.EncodeToString(hash)[:8] }Then use it as:
- // Generate deterministic suffix from content hash for prompt caching - hasher := sha256.New() - hasher.Write([]byte(textContent)) - hasher.Write([]byte(fileName)) - hash := hasher.Sum(nil) - deterministicSuffix := hex.EncodeToString(hash)[:8] + // Generate deterministic suffix from content hash for prompt caching + deterministicSuffix := computeDeterministicSuffix(textContent, fileName)Note on collision risk: The 8-character truncation (32 bits) provides ~4 billion unique values. This should be sufficient for typical conversation contexts, but consider increasing to 12-16 characters if you observe collisions in production.
422-428: Duplicate hashing logic - use the same helper function.This is identical to the text file hashing logic above (lines 393-399). If you extract the helper function suggested in the previous comment, apply it here as well:
- // Generate deterministic suffix from content hash for prompt caching - hasher := sha256.New() - hasher.Write([]byte(jsonContent)) - hasher.Write([]byte(directoryName)) - hash := hasher.Sum(nil) - deterministicSuffix := hex.EncodeToString(hash)[:8] + // Generate deterministic suffix from content hash for prompt caching + deterministicSuffix := computeDeterministicSuffix(jsonContent, directoryName)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pkg/aiusechat/openai/openai-convertmessage.go(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Build for TestDriver.ai
🔇 Additional comments (1)
pkg/aiusechat/openai/openai-convertmessage.go (1)
9-9: LGTM!The addition of
crypto/sha256andencoding/heximports is appropriate for implementing deterministic hash-based suffixes.Also applies to: 11-11
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
frontend/app/view/codeeditor/schemaendpoints.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/app/view/codeeditor/schemaendpoints.ts (2)
frontend/app/store/global.ts (1)
getApi(826-826)frontend/util/endpoints.ts (1)
getWebServerEndpoint(10-10)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
- GitHub Check: Build for TestDriver.ai
No description provided.